package org.example.design.build02.itl.impl;

import org.example.design.build01.itf.Matter;
import org.example.design.build02.itl.IMenu;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname DecorationPackageMenu
 * @Description 建造者核心类
 * @Date 2020/11/2 11:02 上午
 * @Created by xiangjd
 */
public class DecorationPackageMenu implements IMenu {
    //装修清单
    private List<Matter> list = new ArrayList<Matter>();
    //装修初始价格
    private BigDecimal price = BigDecimal.ZERO;
    //装修面积
    private BigDecimal area;
    //装修种类（现代简约，欧式豪华..）
    private String grade;

    private DecorationPackageMenu() {
    }

    public DecorationPackageMenu(Double area, String grade) {
        this.area = new BigDecimal(area);
        this.grade = grade;
    }

    @Override
    public IMenu appendFloor(Matter matter) {
        list.add(matter);
        price = price.add(area.multiply(new BigDecimal(1.4)).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendCelling(Matter matter) {
        list.add(matter);
        price = price.add(area.multiply(new BigDecimal(0.2)).multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendCoat(Matter matter) {
        list.add(matter);
        price = price.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public IMenu appendTitle(Matter matter) {
        list.add(matter);
        price = price.add(area.multiply(matter.price()));
        return this;
    }

    @Override
    public String getDetail() {
        StringBuilder detail = new StringBuilder("\r\n-------------------------------------------------------\r\n" +
                "装修清单" + "\r\n" +
                "套餐等级：" + grade + "\r\n" +
                "套餐价格：" + price.setScale(2, BigDecimal.ROUND_HALF_UP) + " 元\r\n" +
                "房屋面积：" + area.doubleValue() + " 平米\r\n" +
                "材料清单：\r\n");

        for (Matter matter : list) {
            detail.append(matter.scene()).append("：").append(matter.brand()).append("、").append(matter.model()).append("、平米价格：").append(matter.price()).append(" 元。\n");
        }
        return detail.toString();
    }
}
